package com.quanyan.ic.datacenter.dao.impl;

import com.github.ltsopensource.core.commons.utils.DateUtils;
import com.quanyan.ic.datacenter.dao.PlaceDao;
import com.quanyan.ic.datacenter.dao.PlaceUnitLightOpSourceDao;
import com.quanyan.ic.datacenter.mapper.icData.PlaceUnitLightOpSourceMapper;
import com.quanyan.ic.datacenter.mapper.icData.entity.PlaceUnitLightOpSource;
import com.quanyan.ic.datacenter.model.LightOp;
import com.quanyan.ic.datacenter.model.PlaceUnitInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * Created by Administrator on 2017/8/28.
 */
@Repository
public class PlaceUnitLightOpSourceDaoImpl implements PlaceUnitLightOpSourceDao {

    @Autowired
    private PlaceUnitLightOpSourceMapper placeUnitLightOpSourceMapper;

    @Autowired
    private PlaceDao placeDao;


    public Integer insert(LightOp op){
        PlaceUnitLightOpSource placeUnitLightOpSource = new PlaceUnitLightOpSource();
        placeUnitLightOpSource.setPlaceName(op.getPlaceName());
        placeUnitLightOpSource.setPlaceId(op.getPlaceId());

        PlaceUnitInfo placeUnitInfo = placeDao.getPlaceUnitInfo(op.getSiteId());
        placeUnitLightOpSource.setPlaceUnitId(op.getSiteId());
        placeUnitLightOpSource.setPlaceUnitName(placeUnitInfo.getPlaceUnitName());
        if(placeUnitInfo.getCategoryId() != null)
            placeUnitLightOpSource.setCategoryId(placeUnitInfo.getCategoryId().intValue());
        placeUnitLightOpSource.setCategoryName(placeUnitInfo.getCategoryName());
        placeUnitLightOpSource.setCityId(placeUnitInfo.getCityId());
        placeUnitLightOpSource.setCityName(placeUnitInfo.getCityName());
        placeUnitLightOpSource.setOpType(op.getType().byteValue());
        placeUnitLightOpSource.setOpStatus(op.getStatus().byteValue());
        placeUnitLightOpSource.setOpTime(DateUtils.parseYMD_HMS(op.getTime()));
        placeUnitLightOpSource.setOpSuccess(op.isSuccess());

        placeUnitLightOpSourceMapper.insertSelective(placeUnitLightOpSource);
        return placeUnitLightOpSource.getId();

    }

}
